package com.polaris.live.adapter.party

import android.view.LayoutInflater
import android.view.ViewGroup
import com.blankj.utilcode.util.StringUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.R
import com.polaris.live.adapter.party.ModifyPriceTitleAdapter.ModifyPriceTitleHolder
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.databinding.AdapterModifyPriceTitleBinding
import com.polaris.live.resp.back_resp.LivePartyGamePriceVo
import com.polaris.live.translation.R.string
import com.polaris.live.utils.CommonUtils

/**
 * ModifyPriceTitleAdapter
 *
 * @author Created by 天晴 on 2024/3/19 16:30
 * @since 1.0.0
 */
class ModifyPriceTitleAdapter : BaseQuickAdapter<LivePartyGamePriceVo, ModifyPriceTitleHolder>(0) {

    private var lastPosition = 0

    fun setClickPosition(position: Int) {
        lastPosition = position
        notifyDataSetChanged()
    }

    override fun onCreateDefViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): ModifyPriceTitleHolder {
        return ModifyPriceTitleHolder(
            AdapterModifyPriceTitleBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun convert(holder: ModifyPriceTitleHolder, item: LivePartyGamePriceVo) {
        val position = holder.layoutPosition
        if (lastPosition == position) {
            holder.binding.imgDm.alpha = 1.0f
        } else {
            holder.binding.imgDm.alpha = 0.4f
        }
        holder.binding.imgDm.setImageResource(CommonUtils.invokeGameRewardIcon(data[position].assetType))

        holder.binding.bgRl.apply {
            if (position == lastPosition) {
                setBackgroundResource(R.drawable.r8_back_fe194c_tok)
            } else {
                setBackgroundResource(R.drawable.r8_back_f8f8f8_tok)
            }
        }

        holder.binding.tvRewardText.text = when (data[position].assetType) {
            CommonConst.PartyAssetType.DIAMOND -> StringUtils.getString(string.diamond_string)
            CommonConst.PartyAssetType.COIN -> StringUtils.getString(string.game_beans_string)
            CommonConst.PartyAssetType.FREE -> StringUtils.getString(string.free)
            else -> ""
        }
    }

    inner class ModifyPriceTitleHolder(val binding: AdapterModifyPriceTitleBinding) :
        BaseViewHolder(binding.root) {

    }
}